<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>供应商类别</title>
    <link rel="stylesheet" href="../../../../public/dist/css/layui.css">
</head>

<body>

    <form class="layui-form" action="" id="example" lay-filter="example">
        <div class="select common">
            <div class="select-title"> 物料仓库</div>
            <div class="select-con">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 105px;">供应商类型名称:</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input input-d   ming" name="name" placeholder="输入供应商类型名称">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 105px;">是否底层:</label>
                        <div class="layui-input-inline" id="a">
                            <input type="radio" name="ifBottom" value="是" title="是">
                            <input type="radio" name="ifBottom" value="否" title="否">
                        </div>
                    </div>
                </div>




                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 105px;">是否顶层:</label>
                        <div class="layui-input-inline" id="b">
                            <input type="radio" name="ifTop" value="是" title="是">
                            <input type="radio" name="ifTop" value="否" title="否">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 105px;">上层类别名称:</label>
                        <div class="layui-input-inline ">
                            <select name="parentName" lay-filter="shiss" class="superior">
                                        <option value="">---请选择---</option>
                                        
                                 </select>
                        </div>
                    </div>
                </div>


                <div class="select-btn" style="margin-left:30px;">
                    <div class="layui-bg-green comquery queding" id="queding">确定</div>
                    <div class="layui-bg-green comquery cancels">取消</div>
                </div>
            </div>
        </div>
    </form>
</body>
<script src="../../../../js/module/jquery-3.4.1.min.js"></script>
<script src="../../../../public/dist/layui.js" charset="utf-8"></script>
<script src="../../../../js/common/api.js"></script>

</html>

<script>
    layui.use(["table", "laydate", "form"], function() {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            obj = {},
            table = layui.table;



        //取消
        $(".cancels").click(function() {
            window.location.href = "../suppliercategory.html";
        });

        obj.parentName = "";
        obj.parentId = "";

        //上级仓库
        noAjax("coa/getSuppliersTypeList", {}, "get").done(function(resp) {
            console.log(resp.ipage.records)
            $.each(resp.ipage.records, function(v, item) {
                $(".superior").append('<option  value="' + item.id + '">' + item.name + '</option>')
            })
            form.render('select');
            return
        }).fail(function(err) {
            console.log(err)
        });

        form.on('select(shiss)', function(data) {
            obj.parentName = data.elem[data.elem.selectedIndex].text;
            obj.parentId = data.value;
            if (data.value == "") {
                obj.parentName = "";
            }
            return
        });

        //编辑
        var urls = window.location.search;
        urls = urls.substring(4);
        console.log(urls)
        noAjax("coa/getSuppliersTypeList", {
            id: urls
        }, "get").done(function(resp) {

            form.val("example", resp.ipage.records[0]);

            form.render('select');


            return
        }).fail(function(err) {
            console.log(err)
        });



        $("#queding").click(function() {

            if ($(".ming").val() == "") {
                alerts("请输入供应商类型名称")
                return
            }
            if ($('#a input[type="radio"]:checked').val() == "") {
                alerts("请选择是否底层")
                return
            }
            if ($('#b input[type="radio"]:checked').val() == "") {
                alerts("请选择是否顶层")
                return
            }


            obj.name = $(".ming").val();
            obj.ifTop = $('#b input[type="radio"]:checked').val();
            obj.ifBottom = $('#a input[type="radio"]:checked').val();


            if (urls != "") {
                obj.id = urls;
                handleAjax("coa/updateSuppliersType", obj, "POST").done(function(resp) {
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function() {
                        window.location.href = "../suppliercategory.html";
                    }, 1500)
                    return
                }).fail(function(err) {
                    console.log(err)
                });

            } else {
                handleAjax("coa/addSuppliersType", obj, "POST").done(function(resp) {
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function() {
                        window.location.href = "../suppliercategory.html";
                    }, 1500)
                    return
                }).fail(function(err) {
                    console.log(err)
                });
            }
        });
    });
</script>